home *** CD-ROM | disk | FTP | other *** search
/ s-gikan2.maizuru-ct.ac.jp / s-gikan2.maizuru-ct.ac.jp.zip / s-gikan2.maizuru-ct.ac.jp / pub / old / ncvc351d_install.exe / {app} / scripts / change_G90G91.pl < prev    next >
Perl Script  |  2007-06-22  |  4KB  |  188 lines

  1. #! /usr/bin/perl
  2.  
  3. #  ÉΓæ╬ì└òWîn(G90)é╞æèæ╬ì└òWîn(G91)é≡ôⁿéΩæ╓éªéΘâXâNâèâvâg  #
  4. #  Ver.1.300
  5.  
  6. #######################################
  7. # G90é≡G91é╔é╖éΘÅΩìçé═1,é╡é╚éóÅΩìçé═0
  8. $G90toG91= 1;
  9.  
  10. # G91é≡G90é╔é╖éΘÅΩìçé═1,é╡é╚éóÅΩìçé═0
  11. $G91toG90= 1;
  12.  
  13. # ì└òWé≡żÉöô_ò\Īé╖éΘÅΩìçé═ 0
  14. # 1/1000ò\Īé╖éΘÅΩìçé═ 1
  15. # é≡É▌ÆΦé╡é─é¡é╛é│éóüB
  16. $coordinateNotation= 0;
  17.  
  18. #######################################
  19.  
  20. %XYZ= ("X",0,"Y",1,"Z",2,"R",2);
  21.  
  22. $pre_file= $ARGV[0];
  23. $out_file= $ARGV[1];
  24. open(IN,$pre_file);
  25. open(OUT,">$out_file");
  26.  
  27. $kotei_flag= 0;
  28. $initZ= 0;
  29. while(<IN>){
  30.     if(!/^N?[0-9\s]*[\(\%]/){
  31.         $jouken= '([XYZ])([^A-Z\s]+)';
  32.  
  33.         if(/G92/){
  34.             while(/$jouken/g){ $abso[$XYZ{$1}]= $2; }
  35.         }
  36.         if(/G9([01])/){ $G90G91= $1; }
  37.         if(/G99/){ $return_R= 1;}
  38.  
  39.         if($kotei_flag == 1){
  40.             $kotei_flag= koteiCycle_cancel($_);
  41.             if($kotei_flag == 0){ $abso[2]= $initZ; }
  42.         }
  43.         else{ $kotei_flag= koteiCycle_start($_); }
  44.         $initZ= $abso[2];
  45.  
  46.         if($G90G91 == 0 and $G90toG91 == 1){
  47.             s/G90/G91/;
  48.             if($kotei_flag == 1){
  49.                 if(/R([^A-Z\s]+)/){
  50.                     $R= $1;
  51.                     $incli_R= marume($R,$initZ,'-');
  52.                     $_= $`."R".$incli_R.$';
  53.                     if($return_R == 1){
  54.                         $initZ = $R;
  55.                         $return_R = 0;
  56.                     }
  57.                 }
  58.                 else{ $R= $initZ; }
  59.                 if(/Z([^A-Z\s]+)/){
  60.                     $incl= marume($1,$R,'-');
  61.                     $_= $`."Z".$incl.$';
  62.                 }
  63.                 $jouken= '([XY])([^A-Z\s]+)';
  64.             }
  65.             if(!/G92/){
  66.                 $new_line= "";
  67.                 while(/$jouken/){
  68.                     ($pre_line,$char,$num,$_)= ($`,$1,$2,$');
  69.                     $incl= marume($num,$abso[$XYZ{$char}],'-');
  70.                     $abso[$XYZ{$char}]= $num;
  71.                     $new_line= $new_line.$pre_line.$char.$incl;
  72.                 }
  73.                 $_= $new_line.$_;
  74.             }
  75.         }
  76.  
  77.         elsif($G90G91 == 0 and $G90toG91 == 0){
  78.             if($kotei_flag == 1){
  79.                 if(/R([^A-Z\s]+)/){
  80.                     $R= $1;
  81.                     if($return_R == 1){
  82.                         $initZ= $R;
  83.                         $return_R= 0;
  84.                     }
  85.                 }
  86.                 else{ $R= $initZ; }
  87.                 $jouken= '([XY])([^A-Z\s]+)';
  88.             }
  89.             if(!/G92/){
  90.                 while(/$jouken/g){
  91.                     ($char,$num)= ($1,$2);
  92.                     $abso[$XYZ{$char}]= $num;
  93.                 }
  94.             }
  95.         }
  96.  
  97.         elsif($G90G91 == 1 and $G91toG90 == 1){
  98.             s/G91/G90/;
  99.  
  100.             if($kotei_flag == 1){
  101.                 if(/R([^A-Z\s]+)/){
  102.                     $abso_R= marume($1,$initZ);
  103.                     $_= $`."R".$abso_R.$';
  104.                     if($return_R == 1){
  105.                         $initZ= $abso_R;
  106.                         $return_R= 0;
  107.                     }
  108.                 }
  109.                 else{ $abso_R= $initZ; }
  110.                 if(/Z([^A-Z\s]+)/){
  111.                     $absol= marume($1,$abso_R);
  112.                     $_= $`."Z".$absol.$';
  113.                 }
  114.                 $jouken= '([XY])([^A-Z\s]+)';
  115.             }
  116.  
  117.             if(!/G92/){
  118.                 $new_line= "";
  119.                 while(/$jouken/){
  120.                     ($pre_line,$char,$num,$_)= ($`,$1,$2,$');
  121.                     $abso[$XYZ{$char}]= marume($num,$abso[$XYZ{$char}]);
  122.                     $new_line= $new_line.$pre_line.$char.$abso[$XYZ{$char}];
  123.                 }
  124.             }
  125.             $_= $new_line.$_;
  126.         }
  127.  
  128.         elsif($G90G91 == 1 and $G91toG90 == 0){
  129.             if($kotei_flag == 1){
  130.                 if(/R([^A-Z\s]+)/){
  131.                     $abso_R= marume($1,$initZ);
  132.                     if($return_R == 1){
  133.                         $initZ= $abso_R;
  134.                         $return_R= 0;
  135.                     }
  136.                 }
  137.                 $jouken= '([XY])([^A-Z\s]+)';
  138.             }
  139.  
  140.             if(!/G92/){
  141.                 while(/$jouken/g){
  142.                     ($char,$num)= ($1,$2);
  143.                     $abso[$XYZ{$char}]= marume($num,$abso[$XYZ{$char}]);
  144.                 }
  145.             }
  146.         }
  147.  
  148.     }
  149.     print OUT;
  150. }
  151.  
  152. close(OUT);
  153. close(IN);
  154.  
  155.  
  156. sub marume{
  157.     my ($num1,$num2,$enzanshi)= @_;
  158.     my $num;
  159.     
  160.     if($coordinateNotation == 1){
  161.         if($enzanshi eq '-'){ $num= $num1 - $num2; }
  162.         else{ $num= $num1 + $num2; }
  163.         return int($num);
  164.     }
  165.     else{
  166.         $num1 *= 1000;
  167.         $num2 *= 1000;
  168.         $num1= int($num1);
  169.         $num2= int($num2);
  170.         if($enzanshi eq '-'){ $num= ($num1 - $num2) / 1000; }
  171.         else{ $num= ($num1 + $num2) / 1000; }
  172.         if($num !~ /\./ and $num != 0){ $num= $num."\.";}
  173.         return $num;
  174.     }
  175.  
  176. sub koteiCycle_start{
  177.     ($_) = @_;
  178.     if(/G7[346]/ or /G8[1-9]/){ return 1; }
  179.     else{ return 0; }
  180. }
  181.  
  182. sub koteiCycle_cancel{
  183.     ($_) = @_;
  184.     if(/G80/ or /G0*[0123][A-Z\s]/ or /G33/){ return 0; }
  185.     else{ return 1; }
  186. }
  187.